<?php
require("conexao.php");
/*if (!isset($_SESSION["user"]["LOGIN"]) and !isset($_SESSION["user"]["SENHA"]))
	{
 print "<script type= 'text/javascript'> location.href = 'index.php?link=7'
 </script>";
	} */

if (isset($_SESSION["user"]["LOGIN"]) and isset($_SESSION["user"]["SENHA"])){
$acao = "Alterar";
$id = $_SESSION["user"]["ID"];
$sql = "select * from usuario where idusuario = $id";
$resultado = mysql_query ($sql);
$linha = mysql_fetch_array($resultado);

$nome = $linha["nome"];
$email = $linha["email"];
$senha = $linha["senha"];
$login = $linha["login"];
$data_cad = $linha["data_cad"];

}else{
$nome = "";
$email = "";
$senha = "";
$login = "";
$data_cad = "";
}
if (isset($_GET["acao"])){
$acao = $_GET["acao"];
}else{
$acao = "";
}
if (isset($_GET["id"])){
$id = $_GET["id"];
}else{
$id = "";
}



?>

<script type="text/javascript">
try{
xmlhttp = new XMLHttpRequest();
}
catch(ee){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E){
xmlhttp = false;
}
}
}
div_base = "";
valor = 0;
function abre(arquivo,metodo,div){
valor++;
div_base = div;
xmlhttp.open(metodo,arquivo+"&n="+valor);
xmlhttp.onreadystatechange=conteudo
xmlhttp.send(null)
}
function conteudo() {
nova_div = div_base;
document.getElementById(nova_div).innerHTML="verificando..."
if (xmlhttp.readyState==4){
document.getElementById(nova_div).innerHTML=xmlhttp.responseText
}
}
</script>
</head>

<body>
<div id="tabela-cad">
<div id="aba"> Cadastro</div>
  <form id="formulario" name="formulario" onSubmit="return validar();" method="post" action="op_cliente.php">
      <table width="38%" border="0" align="center">
        <tr>
          <td width="204">*Login:</td>
          <td width="320" colspan="2">
          <input type="text" name="txt_login" value="<?php echo $login ?>" onBlur="javascript: abre('consulta.php?txt_login='+document.formulario.txt_login.value,'GET','conteudo');">              </td>
          </tr>
        <tr>
          <td>*Senha:</td>
          <td><input name="txt_senha" type="password" id="txt_senha" maxlength="30" value= "<?php echo $senha ?>" /></td>
          </tr>
        <tr>
          <td>*Confirma:</td>
          <td colspan="2"><input name="txt_confirma" type="password" id="txt_confirma" maxlength="30" value= "<?php echo $senha ?>" /></td>
          </tr>
        <tr>
          <td>*Nome: </td>
          <td colspan="2"><label>
            <input name="txt_nome" type="text" id="txt_nome" maxlength="30" value= "<?php echo $nome ?>" />
          </label></td>
        </tr>
        <tr>
          <td>*Email: </td>
          <td colspan="2"><label>
          <input type="text" name="txt_email" maxlength="30" value="<?php echo $email ?>" onBlur="javascript: abre('consulta2.php?txt_email='+document.formulario.txt_email.value,'GET','conteudo2');">  
              </label></td>
        </tr>
        <?php if($acao != ""){  ?>
        <tr>
          <td>Data de Cadastro:</td>
          <td colspan="2"><label>
            <?php echo $data_cad ?>
          </label> </td>
        </tr>
        <?php }  ?>
        <tr>
          <td colspan="3"><label>
         <div id="alerta"></div>
         <div id="conteudo"></div>
         <div id="conteudo2"></div>
              * Campos de preenchimento obrigatório
                <div align="center">
                <input name="id" type="hidden" value="<?php echo $_SESSION["user"]["ID"]; ?>" />
                <input name="acao" type="hidden" value="<?php
				 if ($acao != "") 
				 {echo $acao;
				 } else {
				  echo "Inserir";
				  } ?>" />
                <input type="submit" name="Submit" value="<?php
				 if ($acao != "") 
				 {echo $acao;
				 } else {
				  echo "Inserir";
				  } ?>" />
                  <input type="button" value="voltar" onclick=javascript:window.history.back()>
              </div>
            </label></td>
        </tr>
      </table>
  </form>
</div>
</body>
</html>
